package cn.closeli.qrencode;

import android.app.Activity;
import android.graphics.Bitmap;
import android.os.Bundle;
import android.util.Log;
import android.widget.ImageView;
import android.widget.TextView;

public class MainActivity extends Activity {
    private static final String TAG = MainActivity.class.getSimpleName();
    private TextView mTextView;
    private ImageView mImageView;
    private QRCodeWriter mQRCodeWriter;
    private Bitmap mBitmap;
    private long startTime;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
//        mBitmap = Bitmap.createBitmap(580, 580, Bitmap.Config.ARGB_8888);

        mQRCodeWriter = new QRCodeWriter();
//        mQRCodeWriter.nativeGenColorStripes(mBitmap);
        initViews();
        new Thread(new Runnable() {
            @Override
            public void run() {
                startTime = System.currentTimeMillis();
//                mQRCodeWriter.nativeCreateQRCodeBitmap(mBitmap);
//                mQRCodeWriter.nativeCreateQRCode(mBitmap);
                String content = "Abdsfaefasdfasrefa!221223!@#W#@##@Rafsafsdfsdfsdfsdfsdfkljlfjdskjfs";
                mBitmap = mQRCodeWriter.createQRCodeBitmap(content, 500);
                Log.e(TAG, "QRCodeWriter.nativeCreateQRCodeBitmap spend " +
                        (System.currentTimeMillis() - startTime) + " ms");
                runOnUiThread(new Runnable() {
                    @Override
                    public void run() {
                        mImageView.setImageBitmap(mBitmap);
                    }
                });
            }
        }).start();
    }

    private void initViews() {
        mTextView = (TextView) findViewById(R.id.tv_msg);
        mTextView.setText(mQRCodeWriter.nativeStringFromJni());

        mImageView = (ImageView) findViewById(R.id.iv_qrcode);
    }
}
